<template>
  <div class="agreement-detail" v-loading="isAllLoading">
    <el-row class="content-wrap" v-if="objDetail.agreementManage">
      <h3 class="content-wrap__title">
        协议ID：{{ objDetail.agreementManage.id }}
        <span class="content-wrap__tag" v-if="
            objDetail.agreementManage.status === 3 ||
            objDetail.agreementManage.status === 2
          ">{{ objDetail.agreementManage.status | parseAgreementStatus }}</span>
      </h3>
      <el-col :span="24"  class="info-box">
        <el-row>
          <el-col :span="7">协议类型：{{
              objDetail.agreementManage.agreementType | parseAgreementType
            }}</el-col>
          <el-col :span="7">协议类别：{{objDetail.agreementManage.agreementCategory | agreementCategoryFilter}}</el-col>
          <el-col :span="10">计价方式：{{
              objDetail.agreementManage.priceType | parsePriceType
            }}</el-col>
          <!-- <el-col :span="8"
            >协议所属区：{{ objDetail.agreementManage.deptCode }}</el-col
          > -->
        </el-row>
        <el-row>
          <el-col :span="7">公司名称：{{ objDetail.agreementManage.companyName }}</el-col>
          <el-col :span="7">统一社信用代码：
            {{ objDetail.agreementManage.companyOwnerUscCode }}</el-col>
          <el-col :span="10">联系人：{{ objDetail.agreementManage.companyContactUser}}
            <span v-if="objDetail.agreementManage.companyContactUser && objDetail.agreementManage.companyContactPhone">/</span>
            {{objDetail.agreementManage.companyContactPhone}}</el-col>
        </el-row>
        <el-row>
          <el-col v-if="objDetail.agreementManage.carrierType=='C'" :span="7">
            司机姓名：{{ objDetail.agreementManage.supplierName }}</el-col>
          <el-col v-else :span="7">承运商名称：{{ objDetail.agreementManage.supplierName }}</el-col>
          <el-col v-if="objDetail.agreementManage.carrierType=='C'" :span="7">
            身份证号码：{{ objDetail.agreementManage.ownerUscCode }}</el-col>
          <el-col v-else :span="7">统一社信用代码：{{ objDetail.agreementManage.ownerUscCode }}</el-col>
          <el-col :span="10">联系人：{{ objDetail.agreementManage.contactUser}}
            <span v-if="objDetail.agreementManage.contactUser && objDetail.agreementManage.contactPhone">/</span>
            {{objDetail.agreementManage.contactPhone}} </el-col>
        </el-row>
        <el-row v-if="objDetail.agreementManage.status == -1 && custom.pageType === 2" style="padding:5px 0;">
          <el-col :span="7">
            是否交保证金：
            <el-radio-group v-model="modifyData.depositFlag">
              <el-radio :label="0">否</el-radio>
              <el-radio :label="1">是</el-radio>
            </el-radio-group>
          </el-col>
          <el-col :span="17" v-if="modifyData.depositFlag == 1" class="new-el-select">
            保证金规则：
            <el-select v-model="modifyData.depositRuleName" clearable @focus="handleDepoistRuleClick"
              @change="handleDepoistRuleChange" :loading="depoistRuleLoading">
              <el-option v-for="option in depoistRuleOptions" :key="option.id" :label="option.name"
                :value="option.name">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row v-else>
          <el-col :span="7" v-if="objDetail.agreementManage.depositFlag == 0 ">是否交保证金：否</el-col>
          <el-col :span="7" v-else-if="objDetail.agreementManage.depositFlag ==1 ">是否交保证金：是</el-col>
          <el-col :span="7" v-if="objDetail.agreementManage.depositFlag == 1">
            保证金规则名称：{{objDetail.agreementManage.depositRuleName}}</el-col>
          <el-col :span="10" v-if="(objDetail.paymentAmount && objDetail.paymentAmount.payableAmount) ||
           (objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.payableAmount)">
            <span>保证金：</span>
            <div v-if="objDetail.querySaasParam.scene ==1" style="display:inline-block;">
              <span v-if="objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.payableAmount"><span class="line_content">{{objDetail.biddingDepositInfo.payableAmount}}</span><span>元-投标</span></span>&nbsp;
              <span v-if="objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.paidStatus == 1">（待缴）</span>
              <span v-if="objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.paidStatus == 3">（已缴）</span>
              <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.payableAmount"><span class="line_content">{{objDetail.paymentAmount.payableAmount}}</span><span>元-中标</span>
              <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.paidStatus == 1">（待缴）</span>
              <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.paidStatus == 3">（已缴）</span>
                <el-tooltip placement="top" v-if="objDetail.paymentAmount && objDetail.paymentAmount.payableAmount">
                  <div slot="content"><span v-if="objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.payableAmount">参与招投标需先缴纳<span>{{objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.payableAmount}}</span>元投标保证金，<br/></span>
                    <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.payableAmount">若中标，收到中标通知后缴纳<span>{{objDetail.paymentAmount.payableAmount}}</span>元中标保证金。</span></div>
                  <i class="el-icon-question" style="color:#999999;"></i>
                </el-tooltip>
              </span>
            </div>
            <div style="display:inline-block;" v-if="objDetail.querySaasParam.scene ==2">
              <span>{{objDetail.paymentAmount ?objDetail.paymentAmount.payableAmount:""}}元</span>
              <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.paidStatus == 1">（待缴）</span>
              <span v-if="objDetail.paymentAmount && objDetail.paymentAmount.paidStatus == 3">（已缴）</span>
            </div>
            <img v-if="objDetail.paymentAmount && objDetail.paymentAmount.paidStatus==2" style="width: 48px;vertical-align: sub;" src="../../../../static/img/trade/miaojiao_d.png" alt=""> 
            <el-popover
            placement="right"
            trigger="click">
            <div v-for="(item,index) in depositQueryResult" :key="index">
              <div class="clearfix">
                <div style="float:left">
                   <img style="vertical-align: middle;" v-if="item.type == '1'" src="../../../../static/img/trade/jiaona.png" alt=""> 
                   <img style="vertical-align: middle;" v-else-if="item.type == '2'" src="../../../../static/img/trade/couchu.png" alt=""> 
                   <img style="vertical-align: middle;" v-else-if="item.type == '3'" src="../../../../static/img/trade/shuhui.png" alt=""> 
                   <b style="margin-left:3px">
                     {{item.typeName}}&nbsp;({{item.sceneName}}{{item.bidStepName}}保证金)
                   </b>
                </div>
                <div style="float:right">
                  <b v-if="item.type == '1'">{{item.payAmount}}元</b>
                  <b v-else-if="item.type == '2'" >{{item.deductAmount}}元</b>
                  <b v-else-if="item.type == '3'">{{item.returnAmount}}元</b>
                </div>
              </div>
              <div v-if="item.type == '1'">
                <p style="color: #a1a1a1;margin-left:26px;font-size:14px">
                    缴纳时间：&nbsp;{{item.payTime}}<br/>
                    支付方式：&nbsp;{{item.payTypeName}}<br/>
                    结算流水号：&nbsp;{{item.paySerialNumber}}<br/>
                    预计可赎回时间：&nbsp;{{item.payCallableTime}}<br/>
                </p>
              </div>
              <div v-else-if="item.type == '2'">
                 <p style="color: #a1a1a1;margin-left:26px;font-size:14px">
                    扣除时间：&nbsp;{{item.deductTime}}<br/>
                    扣除原因：&nbsp;{{item.deductReason}}<br/>
                    结算流水号：&nbsp;{{item.paySerialNumber}}<br/>
                </p> 
              </div>
              <div v-else-if="item.type == '3'">
                 <p style="color: #a1a1a1;margin-left:26px;font-size:14px">
                    实际赎回时间：&nbsp;{{item.returnTime}}<br/>
                    结算流水号：&nbsp;{{item.paySerialNumber}}<br/>
                </p> 
              </div>
            </div>
            <el-link type="primary" slot="reference" 
            v-if="(objDetail.paymentAmount && objDetail.paymentAmount.payRecordFlag)||(objDetail.biddingDepositInfo && objDetail.biddingDepositInfo.payRecordFlag)" 
            @click="queryDepositOrderDetails">明细<i class="el-icon-arrow-right"></i></el-link>
            </el-popover>
            
            <el-link type="primary" style="margin-left:5px" @click="queryDepositRule">查看保证金规则</el-link>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">来源：{{ objDetail.agreementManage.source | parseSourceType }}
          </el-col>
          <el-col :span="7">创建人：{{ objDetail.agreementManage.createUser }}</el-col>
          <el-col :span="10">创建时间：
            {{objDetail.agreementManage.createTm | parseTimeStamp}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7" v-if="custom.pageType === 2 && objDetail.agreementManage.status ==-1">签约截止时间：
            <el-date-picker v-model="modifyData.signDeadlineTm" type="datetime" placeholder="签约截止时间"
              format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" style="width: 220px">
            </el-date-picker>
          </el-col>
          <el-col :span="7" v-else-if="objDetail.agreementManage.source==2">
            签约截止时间：{{objDetail.agreementManage.signDeadlineTm | parseTimeStamp}}
          </el-col>
          <el-col :span="17" v-if="custom.pageType === 2">协议有效期：
            <el-date-picker v-model="modifyData.lineEffectTm" type="datetime" placeholder="协议生效时间"
              format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" style="width: 220px"
              :picker-options="pickerStartTime" :disabled="
                modifyData.isDisableStartTime ||
                objDetail.agreementManage.source == 1
              " 
              readonly>
            </el-date-picker>
            至
            <el-date-picker v-model="modifyData.lineExpireTm" type="datetime" placeholder="协议失效时间"
              format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" style="width: 220px" :picker-options="pickerEndTime"
              :disabled="objDetail.agreementManage.source == 1" readonly>
            </el-date-picker>
            <div class="formTips">（选择线路后自动生成协议有效期）</div>
          </el-col>
          <el-col :span="17" v-else>协议有效期：{{
              objDetail.agreementManage.lineEffectTm | parseTimeStamp
            }}&nbsp;&nbsp;至&nbsp;&nbsp;{{
              objDetail.agreementManage.lineExpireTm | parseTimeStamp
            }}</el-col>  
        </el-row>
        <el-row>
          <el-col :span="7" v-if="objDetail.agreementManage.signVehicleNum">车牌号：{{ objDetail.agreementManage.signVehicleNum}}
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-row class="content-wrap">
      <!--  -->
      <h3 class="content-wrap__title">
        线路信息
        <span class="content-wrap__btn" v-if="
            custom.pageType === 2 &&
            objDetail.agreementManage &&
            objDetail.agreementManage.status === 0
          ">
          <!-- 系统创建 -->
          <div v-if="objDetail.agreementManage.source == 1&&objDetail.agreementManage.status !=-1">
            <!-- <el-button type="default" @click="lineStopHandler">终止线路</el-button> -->

            <!-- <el-button
              type="default"
              style="opacity: 0.5"
              @click="delLine(objDetail.agreementManage.source)"
              >删除</el-button
            > -->
            <el-button type="primary" style="
                background: #f5c7a5;
                color: #fff;
                border: solid #f5c7a5 1px;
              " @click="createLine(objDetail.agreementManage.source)">新建</el-button>
          </div>

          <!-- 人工创建 -->
          <div v-else-if="objDetail.agreementManage.source == 2">
            <!-- <el-button type="default" @click="lineStopHandler">终止线路</el-button> -->

            <!-- <el-button
              type="default"
              @click="delLine(objDetail.agreementManage.source)"
              >删除</el-button
            > -->
            <el-button type="primary" @click="createLine(objDetail.agreementManage.source)">新建</el-button>
          </div>
        </span>
      </h3>
      <el-form :model="objDetail" ref="offerForm">
        <div class="listBox1">
          <el-table :data="objDetail.lineList" stripe style="width: 100%"
            :header-cell-style="{ background: '#F7F7F7', color: '#000' }" @selection-change="parseLineSelectionChange" :span-method="objectSpanMethod">
            <el-table-column v-if="custom.pageType === 2" type="selection" width="50" fixed>
            </el-table-column>
            <el-table-column type="index" width="50" label="序号">
            </el-table-column>
            <el-table-column prop="presellId" label="线路ID">
              <template slot-scope="scope">
                <span @click="openLineDetail(scope.row)" class="clickSpan">{{scope.row.presellId}}</span>
              </template>
            </el-table-column>
            <template v-for="item in tableLineColunm">
              <el-table-column v-if="item.lineflag" :formatter="item.formatter" :key="item.id" :label="item.title"
                :min-width="item.width" :show-overflow-tooltip="item.overflowtooltip ? true : false">
                <template slot-scope="scope">
                  <div class="ope-box">
                    <div type="text" size="small">
                      {{ scope.row.presellId }}
                    </div>
                  </div>
                </template>
              </el-table-column>

              <el-table-column v-else :formatter="item.formatter" :key="item.id" :label="item.title" :prop="item.field"
                :width="item.width" :show-overflow-tooltip="item.overflowtooltip ? true : false">
              </el-table-column>
            </template>

            <el-table-column v-if="
                objDetail.agreementManage &&
                custom.pageType == 2
              " label="价格（元/趟）" width="220" fixed="right">
              <template slot-scope="scope">
                <el-form-item :prop="'lineList.' + scope.$index + '.linePrice'" :rules="linerules.linePrice">
                  <el-input-number clearable v-model="scope.row.linePrice" :precision="2" :max="999999999" :min="0">
                  </el-input-number>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column v-if="custom.pageType == 1" label="价格（元/趟）" width="220" fixed="right">
              <template slot-scope="scope">
                {{ scope.row.linePrice }}
              </template>
            </el-table-column>
            <!-- <el-table-column
              fixed="right"
              label="操作"
              width="100"
              label-class-name="ope-th"
              v-if="
                objDetail.agreementManage &&
                objDetail.agreementManage.status === 0 &&
                custom.fromPage !== 'supplier'
              "
            >
              <template slot-scope="scope">
                <div class="ope-box">
                  <el-button
                    @click="changeMile(scope.row)"
                    type="text"
                    size="small"
                    >调整里程</el-button
                  >
                </div>
              </template>
            </el-table-column> -->
          </el-table>
        </div>
      </el-form>
    </el-row>
    <!-- 合同信息 -->
    <el-row class="content-wrap">
      <h3 class="content-wrap__title">合同信息</h3>
       <el-table  :data="contractData" stripe style="width: 100%"
        :header-cell-style="{ background: '#F7F7F7', color: '#000' }">
         <el-table-column
          prop="contractName"
          label="合同名称"
          >
          <template slot-scope="scope">{{ scope.row.contractName}}</template>
        </el-table-column>
        <el-table-column
          label="合同状态"
          >
          <template slot-scope="scope">{{ scope.row.status | statusFilter}}</template>
        </el-table-column>
        <el-table-column
          label="创建日期">
         <template slot-scope="scope">{{ scope.row.createTm | timeFilter}}</template>
        </el-table-column>
        <el-table-column
          label="签署日期">
         <template slot-scope="scope">{{ scope.row.signTm | timeFilter}}</template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button  type="text" size="small" v-if="scope.row.status ==1 || scope.row.status ==0">
              <el-link type="primary" :href="scope.row.url" >查看</el-link>
            </el-button>
            <span v-if="scope.row.contractType == 0 && objDetail.agreementManage.status !=3">
                <el-button type="text" size="small" v-if="scope.row.status !=0 && scope.row.status !=1 && scope.row.status !=2" @click="reCreateContract(scope.row)">重新生成</el-button>
            </span>
            <span v-if="scope.row.contractType == 1 && objDetail.agreementManage.status == -1">
                <el-button type="text" size="small" v-if="scope.row.status !=0 && scope.row.status !=1 && scope.row.status !=2" @click="reCreateContract(scope.row)">重新生成</el-button>
            </span>
            <span v-if="scope.row.contractType == 2 && objDetail.agreementManage.status == 0">
                <el-button type="text" size="small" v-if="scope.row.status !=0 && scope.row.status !=1 && scope.row.status !=2" @click="reCreateContract(scope.row)">重新生成</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table> 
    </el-row>  
    <!-- 变更页不显示日志 -->
    <el-row class="content-wrap" v-if="custom.pageType !== 2">
      <h3 class="content-wrap__title">操作日志</h3>

      <el-row class="select-box">
        <el-form :inline="true" :model="selectForm" ref="selectForm">
          <el-form-item label="操作时间" prop="rangeDate" label-width="70px" class="interval-item">
            <el-date-picker v-model="selectForm.rangeDate" type="daterange" range-separator="至" start-placeholder="开始日期"
              end-placeholder="结束日期" value-format="timestamp">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="操作类型" prop="operType" label-width="100px">
            <el-select v-model="selectForm.operType" placeholder="请选择">
              <el-option label="操作" :value="1"></el-option>
              <el-option label="信息变更" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-button type="default" @click="resetForm('selectForm')" style="margin-left: 20px">重置</el-button>
          <el-button type="primary" @click="queryData">查询</el-button>
        </el-form>
      </el-row>

      <el-table v-loading="isLoading" :data="tableData" stripe style="width: 100%"
        :header-cell-style="{ background: '#F7F7F7', color: '#000' }">
        <el-table-column type="index" width="50" label="序号" fixed>
        </el-table-column>
        <el-table-column v-for="item in tableLogColunm" :formatter="item.formatter" :key="item.id" :label="item.title"
          :prop="item.field" :min-width="item.width" :show-overflow-tooltip="item.overflowtooltip ? true : false">
        </el-table-column>
      </el-table>
      <el-pagination @size-change="parseSizeChange" @current-change="parseCurrentChange" :current-page="selectForm.page"
        :page-sizes="[10, 20, 50, 100, 200, 300, 400]" :page-size="selectForm.pageSize"
        layout="prev, pager, next, jumper,sizes,total" :total="total" style="float: right">
      </el-pagination>
    </el-row>
    <div class="btn-box" v-if="
        objDetail.agreementManage &&
        (objDetail.agreementManage.status === 0 || objDetail.agreementManage.status == -1) &&
        custom.fromPage !== 'supplier'
      ">
      <!-- 变更页显示取消 -->
      <el-button type="default" v-if="custom.pageType === 2" class="btn-big" @click="cancelModifyAgreement()">取消
      </el-button>
      <!-- <el-button
        type="default"
        v-if="custom.pageType !== 2"
        class="btn-big"
        @click="relieveAgreement()"
        >解约</el-button
      > -->
      <el-button type="primary" class="btn-big" v-if="custom.pageType === 2" @click="checkForm">确认变更</el-button>
      <!-- <el-button type="primary" class="btn-big" v-else @click="changeAgreement">变更</el-button> -->
    </div>

    <line-new :show.sync="lineNewDialoglineVisible" :storageName="lineNewModifyStorageName" :list="objDetail.lineList" @getlist="addLinelist">
    </line-new>
    <line-detail :showLineDetail.sync="showLineDetail" :lineDetailId.sync="lineDetailId" :lineType="lineType">
    </line-detail>

    <el-dialog title="线路终止" :visible.sync="lineStopVisible" width="600px" @close="closeLineStopDialog"
      :close-on-click-modal="false">
      <el-form :inline="true" label-width="140px" style="padding-top: 10px" :model="lineStopForm"
        :rules="lineStopFormRules" ref="lineStopForm">
        <el-form-item label="终止时间" prop="expiryDate">
          <el-date-picker v-model="lineStopForm.expiryDate" type="datetime" :picker-options="expiryDatePickOptions"
            placeholder="请选择终止时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="lineStopVisible = false">取 消</el-button>
        <el-button type="primary" @click="doLineStopHandler" :loading="lineStopLoading">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="保证金规则" :visible.sync="rulesVisible">
        <div v-html="straightMatter" style="min-height:300px"></div>
    </el-dialog>
  </div>
</template>

<script>
  var Moment = require("moment");
  import * as AgreementCommon from "../../../js/trade/agreementCommon.js";
  import lineNew from "./lineNew.vue";
  import lineDetail from './lineDetail.vue'
  // 存储源数据
  let originalData = "";
  export default {
    props: ["btns", "custom"], // custom.pageType - 1-详情页  2-变更页
    data() {
      let checkPrice = (rule, value, callback) => {
        if (!value) {
          return callback(new Error("请填写价格"));
        }
        if (value < 0) {
          callback(new Error("价格必须大于0"));
        } else {
          callback();
        }
      };
      return {
        lineType: 1,
        lineDetailId: '',
        showLineDetail: false,
        typeNameList: [], //协议类别
        stopPoints: [], //经停信息表
        operationTableData: [], //操作日志
        pageLog: 1,
        totalSizeLog: 0,
        detailForm: {}, //线路详情表单
        detailDialogVisible: false, //线路详情弹框
        // 协议时间规则
        // ①若协议生效时间＞当前时间，可以把协议生效时间往前或往后调整，且协议生效时间＞当前时间。往后调的缩短时间段内的待执行订单关闭
        // ②若协议生效时间≤当前时间，不可调整协议生效时间 - ok
        // ③协议失效时间可以往前或往后调整，且协议失效时间≥协议生效时间，往前调整缩短时间段内的待执行订单关闭
        // 线路有效期与协议有效期重合的时间段，才按协议派单，协议调整有效期后缩短时间段内派的单要全部收回
        pickerStartTime: {
          disabledDate: (time) => {
            let timeStamp = new Date(time).getTime(),
              nowStamp = new Date(new Date() - 24 * 60 * 60 * 1000).getTime();
            return (
              timeStamp < nowStamp || timeStamp > this.modifyData.lineExpireTm
            );
          },
        },
        pickerEndTime: {
          disabledDate: (time) => {
            let timeStamp = new Date(time).getTime(),
              nowStamp = new Date(new Date() - 24 * 60 * 60 * 1000).getTime();
            return (
              timeStamp < nowStamp || timeStamp < this.modifyData.lineEffectTm
            );
          },
        },
        pickerRangeTime: {
          disabledDate: (item) => {
            // console.log("pickerRangeTime", item);
          },
        },
        pickerAdjustActualTime: {
          disabledDate: (time) => {
            let nowStamp = new Date(new Date() - 24 * 60 * 60 * 1000).getTime(),
              timeStamp = new Date(time).getTime();
            return nowStamp > time;
          },
        },
        linerules: {
          linePrice: [{
              validator: checkPrice,
              trigger: "blur"
            },
            // { required: true, message: "请填价格", trigger: "blur" },
            // { min: 0, max: 999999999, message: '报价区间在0-999999999', trigger: 'blur' }
          ],
        },
        objDetail: {
          lineList: [],
        },
        isLoading: false,
        total: 0,
        selectForm: {
          pageSize: 10,
          page: 1,
          operType: "",
          rangeDate: [],
        },
        searchForm: {},
        currentPage4: 1,
        tableData: [],
        contractData:[],
        // 线路
        tableLineColunm: [
          // { field: "combinationNumber", title: "组合编号", width: 100 },
          // { field: "headVehicleNum", title: "需车头数", width: 100 },
          // { field: "bodyVehicleNum", title: "需车挂数", width: 100 },
          // { field: "presellId", title: "线路ID", width: 100, lineflag: true },
          {
            field: "packCode",
            title: "车包号",
            width: 100
          },
          {
            field: "lineCode",
            title: "线路编码",
            width: 140
          },
          {
            field: "lineSource",
            title: "线路来源",
            width: 120,
            formatter(row) {
              //1人工导入、2调度清分
              if (row.lineSource == 1) {
                return "人工导入";
              } else if (row.lineSource == 2) {
                return "调度清分";
              } else {
                return "";
              }
            },
          },
          {
            field: "lineId",
            title: "车次ID",
            width: 100
          },
          {
            field: "fFromTown",
            title: "始发/目的地城市",
            width: 160
          }, // 1
          {
            field: "fCarTypeOrLen",
            title: "车型/车长(m)",
            width: 140
          }, //
          {
            field: "fPlanAllTime",
            title: "计划靠/发/到车时间",
            width: 200
          }, //
          {
            field: "workday",
            title: "发车频率",
            width: 100
          },
          // { field: "fDumpingTrailers", title: "是否甩挂", width: 80 },
          // { field: "fLineType", title: "线路类型", width: 100 },
          {
            field: "totalKm",
            title: "计划里程（KM）",
            width: 160
          },
          // { field: "actualKm", title: "实际里程（KM）", width: 140 },
          {
            field: "startDate",
            title: "线路生效日期",
            width: 120,
            formatter(row) {
              return Moment(row.startDate).format("YYYY-MM-DD");
            },
          },
          {
            field: "endDate",
            title: "线路失效日期",
            width: 120,
            formatter(row) {
              return Moment(row.endDate).format("YYYY-MM-DD");
            },
          },

          {
            field: "expiryDate",
            title: "终止日期",
            width: 160,
            formatter(row) {
              if (row.expiryDate && Moment(row.expiryDate).isValid()) {
                return Moment(row.expiryDate).format("YYYY-MM-DD HH:mm:ss");
              } else {
                return row.expiryDate || "";
              }
            },
          },
        ],
        // 日志
        tableLogColunm: [{
            field: "operChangeTypeName",
            title: "操作类型",
            width: 100
          },
          {
            field: "operDesc",
            title: "内容",
            width: 200
          },
          {
            field: "operUser",
            title: "操作人",
            width: 100
          },
          {
            field: "operTime",
            title: "操作时间",
            width: 180,
            formatter(row) {
              return Moment(row.operTime).format("YYYY-MM-DD HH:mm:ss");
            },
          },
        ],
        // 变更的信息
        modifyData: {
          rangeDate: [],
          lineEffectTm: "",
          lineExpireTm: "",
          delLineList: [],
          addLineList: [],
          isDisableStartTime: false,
          signDeadlineTm: "",
          depositFlag: '',
          depositRuleId: '',
          depositRuleCode: '',
          depositRuleName: '',
          depositRuleVersion: '',
          userScopeValue: ''
        },
        lineSelection: [],
        vehicleSelection: [],
        lineNewDialoglineVisible: false,
        lineNewModifyStorageName: "lineNewModifyStorageName",
        isAllLoading: true,
        lineStopVisible: false, //线路终止弹框
        lineStopForm: {
          expiryDate: null,
        },
        lineStopFormRules: {
          expiryDate: [{
            required: true,
            message: "请选择终止时间",
            trigger: "blur"
          }, ],
        },
        lineStopLoading: false,
        expiryDatePickOptions: {
          disabledDate(value) {
            let current = Moment(new Date());
            let year = current.year();
            let month = current.month();
            let date = current.date();

            let compare = Moment(value);
            let compareYear = compare.year();
            let compareMonth = compare.month();
            let compareDate = compare.date();
            if (compareYear > year) {
              return false;
            } else if (compareYear === year) {
              if (compareMonth > month) {
                return false;
              } else if (compareMonth == month) {
                if (compareDate >= date) {
                  return false;
                }
              }
            }
            return true;
          },
        },
        depoistRuleOptions: [], //保证金规则下拉数据对象
        depoistRuleLoading: false, //保证金数据加载状态
        spanArr: [],
        pos: "",
        depositQueryResult:[],
        rulesVisible:false,
        straightMatter:""
      };
    },
    computed: {},
    created() {},
    mounted() {
      this.queryAgreementTypeName()
      this.getDetail();
      if (this.custom.pageType === 1) {
        this.queryData();
      }
    },
    watch: {
       ruleForm: {
        handler(val) {
          if(val.lineData){
            this.getOrderNumber(val.lineData);
          }
        },
        deep: true,
      },
    },
    filters: {
      parseAgreementType(val) {
        return val == 2 ? "招投标按趟" : "";
      },
      parsePriceType(val) {
        return AgreementCommon.constConfig.priceType[val];
      },
      parseSourceType(val) {
        return AgreementCommon.constConfig.sourceType[val];
      },
      parseAgreementStatus(val) {
        return AgreementCommon.constConfig.agreementStatus[val] || "";
      },
      parseTimeStamp(val) {
        return Moment(val).format("YYYY-MM-DD HH:mm:ss");
      },
      agreementCategoryFilter(val) {
        return AgreementCommon.constConfig.typeNameList[val] || "";
      },
      statusFilter(val){
        var obj = {0:'未签署',1:'已签署',2:'生成中',3:'已过期',4:'已失效',5:'已删除',6:'生成失败'}
        return obj[val] || "";
      },
      timeFilter(data){
        if(data){
            var date = new Date(Number(data));
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var mm =
                    date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var ss =
                    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                return y + "-" + m + "-" + d+" "+h + ":" + mm+":"+ss;
            }else{
            return ""
            }
      }
    },
    methods: {
     //重新生成
     reCreateContract(row){
        let param = {
          id:row.id
        };
        this.$httpExt()
          .post("trade/biddingAgreementManage/reCreateContract", param)
          .then(
            (response) => {
              if (response.succ == "ok") {
                  this.$message({
                    message: '合同正在生成中...！',
                    type: "success"
                  });
                  if(this.custom.pageType ==1){
                    this.top(this).handleRemove("招投标协议详情");
                          this.$nextTick(() => {
                            this.top(this)._createTab(
                              "招投标协议详情",
                              "biddingAgreementDetail",
                              "",
                              "", {
                                id: this.custom.id,
                                pageType: 1,
                                fromPage: "manage",
                              }
                            );
                          });
                  }else{
                    this.top(this).handleRemove("招投标协议变更");
                    this.$nextTick(() => {
                      this.top(this)._createTab(
                        "招投标协议变更",
                        "biddingAgreementDetail",
                        "",
                        "", {
                          id: this.custom.id,
                          pageType: 2,
                          from: "list", // list  detail
                        }
                      );
                    });
                  }
              } else {
                this.$message({
                  message: response.msg,
                  type: "warning"
                });
              }
            },
            (response) => {
              this.$message({
                message: response.msg,
                type: "warning"
              });
            }
          );
     } ,
    //通过列表数据生成一个与行数相同的数组记录每一行设置的合并数
    getOrderNumber(data) {
      this.spanArr = [];
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].combinationNumber === data[i - 1].combinationNumber && data[i].lineSource == 2 && data[i].lineSource == data[i - 1].lineSource) {
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    //合并行
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if(this.custom.pageType === 1){
        if (
          columnIndex === 2 
        ) {
          const _row = this.spanArr[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col,
          };
        }
      } else {
        if (
          columnIndex === 0 ||
          columnIndex === 3 
        ) {
          const _row = this.spanArr[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col,
          };
        }
      }
      
    },
      openLineDetail(row) {
        this.lineDetailId = row.id
        this.lineType = this.objDetail.agreementManage.source == 1 ? 2 : (row.tbpLineId ? 2 : 1)
        this.showLineDetail = true
      },
      /* 查协议类型 */
      queryAgreementTypeName() {
        this.$httpExt().post("trade/AgreementTextManage/queryAgreementTypeName", {})
          .then((response) => {
            if (response.result && response.succ == 'ok') {
              this.typeNameList = response.result
            }
          }, (response) => {});
      },
      //查询日志
      queryLog(row) {
        let param = {
          stayBidId: row.conLineId,
          pageSize: 10,
          page: this.pageLog,
        };
        this.$httpExt()
          .post("/saas/stayBidding/queryStayBidLineLogList", param)
          .then(
            (response) => {
              var result = response.result;
              if (result && response.succ == "ok") {
                this.operationTableData = result.list;
                this.totalSizeLog = result.total;
              } else {
                this.$message({
                  message: response.msg,
                  type: "warning"
                });
              }
            },
            (response) => {
              this.$message({
                message: response.msg,
                type: "warning"
              });
            }
          );
      },
      // 添加线路
      addLinelist(list) {
        console.log("list", list);
        // 选中的线路
        // 选中的线路+已有线路
        // this.objDetail.lineList = this.translateLineInfo(
        //   AgreementCommon.uniqueArray(this.objDetail.lineList.concat(list), "id")
        // );
        // this.objDetail.lineList = this.translateLineInfo(list);
        //调接口查询数据
        this.queryUncheckedLineListByCombinationNumber(list[0]);
      },
      queryUncheckedLineListByCombinationNumber(val){
        let params = {
          combinationNumber: val.combinationNumber,
          lineSource: val.lineSource,
          requireLabelEnum: 2
        }
        this.$httpExt()
          .post("trade/lineManagement/queryUncheckedLineListByCombinationNumber", params)
          .then(
            (response) => {
              if (response.succ == "ok" && response.result) {
                var result = response.result;
                if(result.lineList){
                  this.objDetail.lineList = this.translateLineInfo(result.lineList);
                }
                this.getOrderNumber(this.objDetail.lineList);
                if(result.onlineDate && result.offlineDate){
                  this.modifyData.lineEffectTm = result.onlineDate;
                  this.modifyData.lineExpireTm = result.offlineDate;
                } else {
                  this.modifyData.lineEffectTm = "";
                  this.modifyData.lineExpireTm = "";
                }              
              } else {
                this.$message({ message: response.msg, type: "warning" });
              }
            },
            (response) => {
              this.$message({ message: response.msg, type: "warning" });
            }
        );
    },
      translateLineInfo(lineList) {
        let len = lineList.length;
        for (let i = 0; i < len; i++) {
          const item = lineList[i];
          item.fFromTown = item.originTownName + "/" + item.destinationTownName;
          item.planBerthTime +
            "/" +
            item.planSendTime +
            "/" +
            item.planArriveTime;
          item.fPlanAllTime =
            item.planBerthTime +
            "/" +
            item.planSendTime +
            "/" +
            item.planArriveTime;
          item.fCarTypeOrLen = item.vehicleTypeName + "/" + item.vehicleLength;
          item.fDumpingTrailers = item.dumpingTrailers ? "是" : "否";
          item.fLineType = item.lineType == 1 ? "真实线路" : "预售线路";
        }
        return lineList;
      },
      // 变更
      changeAgreement() {
        this.top(this)._createTab(
          "招投标协议变更",
          "biddingAgreementDetail",
          "",
          "", {
            id: this.custom.id,
            pageType: 2,
            from: "detail", // list  detail
          }
        );
      },
      // 找到 包含tabs的父组件
      top(self_) {
        if (self_.$parent && self_.$parent.tabs) {
          return self_.$parent;
        }
        return this.top(self_.$parent);
      },
      createLine(source) {
        if (source == 1) {
          this.$message({
            message: "此线为系统创建线路，不可编辑",
            type: "warning",
          });
          return;
        }
        // todo 创建线路
        this.lineNewDialoglineVisible = true;
      },
      parseLineSelectionChange(val) {
        console.log("lineSelection", val);
        this.lineSelection = val;
      },
      delLine(source) {
        if (source == 1) {
          this.$message({
            message: "此线为系统创建线路，不可删除",
            type: "warning",
          });
          return;
        }

        if (this.lineSelection.length <= 0) {
          this.$confirm("请选择需要删除的线路!", "提示", {
              confirmButtonText: "确定",
              showCancelButton: false,
              type: "warning",
            })
            .then(() => {})
            .catch(() => {});
          return;
        }

        let lineSourceEqOne = false;
        this.lineSelection.forEach((item) => {
          if (item.lineSource == 2 || item.lineSource == null) {
            //人工导入的线路才能删除
            lineSourceEqOne = true;
          }
        });
        if (lineSourceEqOne) {
          this.$message({
            message: "只有人工导入的线路才能删除",
            type: "warning",
          });
          return;
        }

        this.$confirm("确定删除该线路吗?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",

            type: "warning",
          })
          .then(() => {
            this.modifyData.delLineList = this.lineSelection;
            // 删除当前已选择
            const lineList = this.objDetail.lineList,
              lineSelection = this.lineSelection,
              newLine = [];
            this.objDetail.lineList = AgreementCommon.diffSet(
              lineList,
              lineSelection,
              "id"
            );
          })
          .catch(() => {});
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      getDetail() {
        this.objDetail = {};
        // console.log("custom detail", this.custom);
        this.$httpExt()
          .post("trade/biddingAgreementManage/queryAgreementInfo", {
            id: this.custom.id,
          })
          .then(
            (objResp) => {
              this.isAllLoading = false;
              // console.log(objResp);
              if (objResp && objResp.succ == "ok") {
                originalData = JSON.parse(JSON.stringify(objResp.result));
                this.objDetail = this.translateInfoTableData(objResp.result);
                objResp.result.contractList.forEach(item =>{
                  var channelCode = item.channelCode?item.channelCode:'EOS-TBP-CORE'
                   item.url = BACKGROUND + "contract/transportAgreementForSup/downloadContractNew?contractId=" +
                   item.signId + "&tableName=" + item.contractName + "&channelCode=" + channelCode
                })
                this.contractData = objResp.result.contractList;
                // 处理修改数据
                // 是否为变更页
                this.handleModify();
              } else {
                this.$message({
                  message: objResp.msg,
                  type: "warning"
                });
              }
            },
            (objResp) => {
              this.isAllLoading = false;
              this.$message({
                message: objResp.msg,
                type: "warning"
              });
            }
          );
      },
      queryDepositOrderDetails(){
        let paidOrderIdsList = [];	
        if(this.objDetail.biddingDepositInfo && this.objDetail.biddingDepositInfo.paidOrderId){
          paidOrderIdsList.push(this.objDetail.biddingDepositInfo.paidOrderId);
        }
        if(this.objDetail.paymentAmount && this.objDetail.paymentAmount.paidOrderId){
          paidOrderIdsList.push(this.objDetail.paymentAmount.paidOrderId);
        }
        let paidOrderIds = paidOrderIdsList.join(",");
          this.$httpExt()
          .post("saasDepoist/depositOrder/queryDepositOrderDetails", {
            page: 1,
            pageSize: 100,
            agreementId: this.objDetail.agreementManage.id,
            paidOrderIds: paidOrderIds,
            ruleCode: this.objDetail.querySaasParam.ruleCode,
            vehicleLength: this.objDetail.querySaasParam.vehicleLength,
            userId:this.objDetail.querySaasParam.userId
          })
          .then(
            (objResp) => {
              if (objResp && objResp.succ == "ok") {
                  this.depositQueryResult =objResp.result.queryResult; 
              } else {
                this.$message({
                  message: objResp.msg,
                  type: "warning"
                });
              }
            },
            (objResp) => {
              this.$message({
                message: objResp.msg,
                type: "warning"
              });
            }
          );
      },
      queryDepositRule(){
        this.$httpExt()
          .post("trade/biddingAgreementManage/queryDepositRule", {
            agreementId: this.objDetail.agreementManage.id,
            ruleId: this.objDetail.paymentAmount.ruleId
          })
          .then(
            (objResp) => {
              if (objResp && objResp.succ == "ok") {
                  console.log(objResp)
                  this.straightMatter = objResp.result.straightMatter
                  this.rulesVisible = true;
              } else {
                this.$message({
                  message: objResp.msg,
                  type: "warning"
                });
              }
            },
            (objResp) => {
              this.$message({
                message: objResp.msg,
                type: "warning"
              });
            }
          );
      },
      translateInfoTableData(data) {
        // 处理线路信息
        let lineList = data.lineList;
        this.translateLineInfo(lineList);
        this.getOrderNumber(lineList);
        return data;
      },

      handleModify() {
        this.modifyData.lineEffectTm =
          this.objDetail.agreementManage.lineEffectTm || "";
        this.modifyData.lineExpireTm =
          this.objDetail.agreementManage.lineExpireTm || "";

        if (this.modifyData.lineEffectTm <= new Date().getTime()) {
          this.modifyData.isDisableStartTime = true;
        }
        this.modifyData.signDeadlineTm = this.objDetail.agreementManage.signDeadlineTm || ""

        this.modifyData.depositFlag = this.objDetail.agreementManage.depositFlag || 0;

        if (this.objDetail.agreementManage.depositRuleId) {
          this.handleDepoistRuleClick();
          this.modifyData.depositFlag = 1;
          this.modifyData.depositRuleId = this.objDetail.agreementManage.depositRuleId;
          this.modifyData.depositRuleName = this.objDetail.agreementManage.depositRuleName;
          this.modifyData.depositRuleCode = this.objDetail.agreementManage.depositRuleCode;
          this.modifyData.depositRuleVersion = this.objDetail.agreementManage.depositRuleVersion;
          this.modifyData.userScopeValue = this.objDetail.agreementManage.userScopeValue;

          if (this.objDetail.agreementManage.carrierType && typeof this.objDetail.agreementManage.carrierType ==
            'string') {
            if (this.objDetail.agreementManage.carrierType.toUpperCase() == 'B') {
              this.modifyData.userScopeValue = '1';
            } else if (this.objDetail.agreementManage.carrierType.toUpperCase() == 'C') {
              this.modifyData.userScopeValue = '2';
            }
          }

          if (this.objDetail.agreementManage.userScopeValue) {
            this.modifyData.userScopeValue = this.objDetail.agreementManage.userScopeValue;
          }

        }

        // objDetail.agreementManage.agreementCategory
      },
      cancelModifyAgreement() {
        this.$confirm(
            "确定取消变更协议?取消后，已填写的协议内容不再保留。",
            "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
          .then(() => {
            let id = this.custom.id;
            // from
            // 在详情页点击变更，进入变更页，点击取消，返回到详情页
            // 在列表页点击变更，进入变更页，点击取消，返回到列表页
            if (this.custom.pageType === 2) {
              this.top(this).handleRemove("招投标协议变更");

              let oPage = {
                name: "招投标协议管理",
                tab: "biddingAgreementManage",
                moduleId: "1041504",
              };
              if (this.custom.from === "detail") {
                oPage = {
                  name: "招投标协议详情",
                  tab: "biddingAgreementDetail",
                };
              }
              this.top(this).handleRemove(oPage.name);
              this.$nextTick(() => {
                this.top(this)._createTab(
                  oPage.name,
                  oPage.tab,
                  oPage.moduleId || "",
                  "", {
                    id: id,
                    pageType: 1,
                  }
                );
              });
            }
          })
          .catch(() => {});
      },
      toDetail() {
        let id = this.custom.id;
        if (this.custom.pageType === 2) {
          this.top(this).handleRemove("招投标协议变更");
          this.top(this).handleRemove("招投标协议详情");
          this.$nextTick(() => {
            this.top(this)._createTab(
              "招投标协议详情",
              "biddingAgreementDetail",
              "",
              "", {
                id: id,
                pageType: 1,
              }
            );
          });
        } else {
          this.top(this).handleRemove("招投标协议详情");
          this.$nextTick(() => {
            this.top(this)._createTab(
              "招投标协议详情",
              "biddingAgreementDetail",
              "",
              "", {
                id: id,
                pageType: 1,
              }
            );
          });
        }
      },
      // 确认变更协议
      checkForm() {
        if (
          this.objDetail.agreementManage.agreementType == 2 &&
          this.objDetail.lineList.length > 0
        ) {
          this.$refs["offerForm"].validate((valid) => {
            if (valid) {
              this.confirmChangeAgreement();
            } else {
              this.$message({
                message: "价格有误",
                type: "warning"
              });
              return false;
            }
          });
        } else {
          this.confirmChangeAgreement();
        }
      },
      confirmChangeAgreement() {
        let that = this
        let oParam = {
          id: this.custom.id, // 协议id
          delLineList: [],
          addLineList: [],
          updateLinePriceList: [],
        };
        // 失效时间 <= 生效时间 提示错误 “失效时间需大于生效时间” 1707148800000
        if (this.modifyData.lineExpireTm <= this.modifyData.lineEffectTm) {
          this.$confirm("失效时间需大于生效时间！", "提示", {
              confirmButtonText: "确定",
              showCancelButton: false,
              type: "warning",
            })
            .then(() => {})
            .catch(() => {});
          return;
        }
        if (
          originalData.agreementManage.lineExpireTm !==
          this.modifyData.lineExpireTm
        ) {
          oParam["lineExpireTm"] = this.modifyData.lineExpireTm;
        }
        if (
          originalData.agreementManage.lineEffectTm !==
          this.modifyData.lineEffectTm
        ) {
          oParam["lineEffectTm"] = this.modifyData.lineEffectTm;
        }

        if (originalData.agreementManage.signDeadlineTm != this.modifyData.signDeadlineTm && originalData
          .agreementManage.signDeadlineTm && this.modifyData.signDeadlineTm) {

          if (that.modifyData.signDeadlineTm < Date.parse(new Date())) {
            that.$message({
              message: '签约截止时间需大于当前时间',
              type: "warning"
            });
            return
          } else {
            oParam["signDeadlineTm"] = this.modifyData.signDeadlineTm;
          }
        }

        oParam.depositFlag = this.modifyData.depositFlag;
        if (this.modifyData.depositFlag == 1) {

          if (!this.modifyData.depositRuleId) {
            that.$message({
              message: '请选择保证金规则',
              type: "warning"
            });
            return
          }

          oParam.depositRuleId = this.modifyData.depositRuleId;
          oParam.depositRuleCode = this.modifyData.depositRuleCode;
          oParam.depositRuleName = this.modifyData.depositRuleName;
          oParam.depositRuleVersion = this.modifyData.depositRuleVersion;
          oParam.userScopeValue = this.modifyData.userScopeValue;
        }

        // 线路不能超过50条
        if (this.objDetail.lineList.length > 50) {
          this.$confirm("同一协议可关联多条的线路，最多50条!", "提示", {
              confirmButtonText: "确定",
              // cancelButtonText: '取消',
              showCancelButton: false,
              type: "warning",
            })
            .then(() => {})
            .catch(() => {});
          return;
        }

        // newData oriData add
        // add = newData - oriData
        // del = oriData - newData
        // 线路相关
        let lineList = originalData.lineList;
        lineList.forEach((item) => {
          let flag = false;
          this.objDetail.lineList.forEach((item2) => {
            if (item.id === item2.id) {
              flag = true;
            }
          });
          if (!flag) {
            // this.modifyData.delLineList.push(item)
            oParam.delLineList.push({
              // id: item.id,
              id: item.tbpLineId,
              originTownName: item.originTownName,
              destinationTownName: item.destinationTownName,
              startDate: item.startDate,
              endDate: item.endDate,
              // createTm: item.createTm?new Date(item.createTm).getTime():undefined, //不要删这个字段，要不然变更会报错
            });
          }
        });

        this.objDetail.lineList.forEach((item) => {
          let flag = false;
          lineList.forEach((item2) => {
            if (item.id === item2.id) {
              flag = true;
              if (item.linePrice != item2.linePrice) {
                // oParam.delLineList.push({
                //   // id: item.id,
                //   id: item.tbpLineId,
                //   originTownName: item.originTownName,
                //   destinationTownName: item.destinationTownName,
                //   startDate: item.startDate,
                //   endDate: item.endDate,
                //   createTm: item.createTm,//不要删这个字段，要不然变更会报错
                // });
                oParam.updateLinePriceList.push({
                  id: item.id,
                  combinationNumber: item.combinationNumber,
                  lineCode: item.lineCode,
                  lineId: item.lineId,
                  originProvinceName: item.originProvinceName,
                  originTownName: item.originTownName,
                  originTownCode: item.originTownCode,
                  destinationProvinceName: item.destinationProvinceName,
                  destinationTownName: item.destinationTownName,
                  destinationTownCode: item.destinationTownCode,
                  vehicleTypeName: item.vehicleTypeName,
                  vehicleLength: item.vehicleLength,
                  planBerthTime: item.planBerthTime,
                  planSendTime: item.planSendTime,
                  planArriveTime: item.planArriveTime,
                  workday: item.workday,
                  dumpingTrailers: item.dumpingTrailers,
                  totalKm: item.totalKm,
                  startDate: item.startDate,
                  endDate: item.endDate,
                  // createTm:item.createTm?new Date(item.createTm).getTime():undefined, //不要删这个字段，要不然变更会报错
                  linePrice: item.linePrice,
                  linePattern: item.linePattern, //2021-05-24 新增列表字段
                });
              }
            }
          });
          if (!flag) {
            // this.modifyData.delLineList.push(item)
            oParam.addLineList.push({
              id: item.id,
              combinationNumber: item.combinationNumber,
              lineCode: item.lineCode,
              lineId: item.lineId,
              originProvinceName: item.originProvinceName,
              originTownName: item.originTownName,
              originTownCode: item.originTownCode,
              destinationProvinceName: item.destinationProvinceName,
              destinationTownName: item.destinationTownName,
              destinationTownCode: item.destinationTownCode,
              vehicleTypeName: item.vehicleTypeName,
              vehicleLength: item.vehicleLength,
              planBerthTime: item.planBerthTime,
              planSendTime: item.planSendTime,
              planArriveTime: item.planArriveTime,
              workday: item.workday,
              dumpingTrailers: item.dumpingTrailers,
              totalKm: item.totalKm,
              startDate: item.startDate,
              endDate: item.endDate,
              // createTm: item.createTm?new Date(item.createTm).getTime():undefined, //不要删这个字段，要不然变更会报错
              linePrice: item.linePrice,
              linePattern: item.linePattern, //2021-05-24 新增列表字段
            });
          }
        });




        this.$confirm("确认变更协议内容?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
          .then(() => {
            this.$httpExt()
              .post("trade/biddingAgreementManage/updateAgreement", oParam)
              .then(
                (response) => {
                  if (response && response.succ == "ok") {
                    this.queryData();
                    this.$message({
                      message: "操作成功",
                      type: "success",
                    });
                    this.toDetail();

                    if (oParam.lineExpireTm || oParam.lineEffectTm) {
                      this.$emit(
                        "page",
                        "招投标协议管理",
                        function (resolve) {
                          require(["./biddingAgreementManage.vue"], resolve);
                        },
                        "1041504"
                      );
                    }
                  } else {
                    this.$message({
                      message: response.msg,
                      type: "warning"
                    });
                  }
                },
                (response) => {
                  this.$message({
                    message: response.msg,
                    type: "warning"
                  });
                }
              );
          })
          .catch(() => {});
      },
      queryData() {
        this.page = 1;
        this.searchList();
      },
      parseSizeChange(val) {
        this.selectForm.pageSize = val;
        this.searchList();
      },
      parseCurrentChange(val) {
        this.selectForm.page = val;
        this.searchList();
      },
      currentChange(val) {
        this.page = val; //* this.pageSize
        this.getPageData();
      },
      currentChangeLog(val) {
        this.pageLog = val; //* this.pageSize
        this.queryLog();
      },
      resetSearch() {
        this.$refs["selectForm"].resetFields();
      },
      searchList() {
        let objParam = {
          pageSize: "",
          page: "",
          operType: "",
          // operChangeType: 1,
          protocolId: "",
          startTm: "",
          endTm: "",
        };

        Object.keys(objParam).forEach((key) => {
          objParam[key] = this.selectForm[key];
        });
        objParam["protocolId"] = this.custom.id;
        if (this.selectForm.rangeDate) {
          objParam["startTm"] = this.selectForm.rangeDate[0];
          objParam["endTm"] = this.selectForm.rangeDate[1];
        }

        // 查询列表数据
        this.tableData = [];
        this.isLoading = true;
        this.$httpExt()
          .post("trade/biddingAgreementManage/queryAgreementLog", objParam)
          .then(
            (objResp) => {
              this.isLoading = false;
              if (objResp && objResp.succ === "ok") {
                var result = objResp.result;
                this.total = result.totalRecord;
                if (result.datas && result.datas.length > 0) {
                  this.tableData = this.translateTableData(result.datas);
                }
              } else {
                this.$message({
                  message: objResp.msg,
                  type: "warning"
                });
              }
            },
            (objResp) => {
              this.isLoading = false;
              this.$message({
                message: objResp.msg,
                type: "warning"
              });
            }
          );
      },
      translateTableData(data) {
        let len = data.length;
        for (let i = 0; i < len; i++) {
          const item = data[i];
          // 协议类型 协议类型，0：共建；
          // 协议状态 协议状态，0、生效；1、失效；2、签约已解除；
          item.fOperType = AgreementCommon.constConfig.operType[item.operType];
        }
        return data;
      },
      lineStopHandler() {
        if (this.lineSelection.length <= 0) {
          this.$confirm("请选择需要终止的线路!", "提示", {
              confirmButtonText: "确定",
              showCancelButton: false,
              type: "warning",
            })
            .then(() => {})
            .catch(() => {});
          return;
        }

        if (this.lineSelection.length > 1) {
          this.$message({
            message: "终止不支持多条线路操作，请选择一条线路",
            type: "warning",
          });
          return;
        }
        let lineStop = this.lineSelection[0];

        if (!(lineStop.lineSource == null || lineStop.lineSource == 2)) {
          this.$message({
            message: "此线路不能终止",
            type: "warning",
          });
          return;
        }

        if (lineStop.expiryDate) {
          this.$message({
            message: "此线路已经终止过了，请勿重复操作",
            type: "warning",
          });
          return;
        }

        this.lineStopVisible = true;
      },
      closeLineStopDialog() {
        this.$refs.lineStopForm.resetFields();
      },
      doLineStopHandler() {
        let lineStop = this.lineSelection[0];

        let params = {
          agreementId: this.objDetail.agreementManage.id,
          tbpLineId: lineStop.id,
          lineId: lineStop.presellId,
          expiryDate: this.lineStopForm.expiryDate,
        };

        this.$refs.lineStopForm.validate((boo, obj) => {
          if (boo) {
            params.expiryDate = Moment(params.expiryDate).valueOf(); //时间转换为时间戳
            if (
              Moment(this.lineStopForm.expiryDate).isSameOrBefore(Moment(new Date()))
            ) {
              this.$message({
                message: "终止时间必须大于等于当前时间",
                type: "warning",
              });
              return;
            }

            this.lineStopLoading = true;
            this.$httpExt()
              .post("trade/biddingAgreementManage/updateExpiryLine", params)
              .then(
                (response) => {
                  this.lineStopLoading = false;
                  if (response && response.succ == "ok") {
                    this.lineStopVisible = false;
                    this.$message({
                      message: "终止成功",
                      type: "success",
                    });
                    this.lineSelection = [];
                    this.getDetail();
                  } else {
                    this.lineStopLoading = false;
                    this.$message({
                      message: response.msg,
                      type: "warning"
                    });
                  }
                },
                (response) => {
                  this.lineStopLoading = false;
                  this.$message({
                    message: response.msg,
                    type: "warning"
                  });
                }
              );
          }
        });
      },
      handleDepoistRuleClick() {
        this.depoistRuleLoading = true;
        this.$httpExt().post('saasDepoist/depositRule/select', {
          page: 1,
          pageSize: 1000,
          tenantId: 'TBP',
          scene: 2,
          payModePerson: 3,
          payModeCompany: 3,
          status: 1
        }).then((response) => {
          this.depoistRuleLoading = false;

          if (response.succ == 'ok') {
            this.depoistRuleOptions = response.result.list;
            this.$nextTick(() => {
              if (response.result.list && response.result.list.length > 0) {
                if (!this.modifyData.depositRuleId) {
                  this.modifyData.depositRuleId = response.result.list[0].id;
                  this.modifyData.depositRuleName = response.result.list[0].name;
                  this.modifyData.depositRuleCode = response.result.list[0].ruleCode;
                  this.modifyData.depositRuleVersion = response.result.list[0].version;
                  this.modifyData.userScopeValue = response.result.list[0].userScopeValue;
                }
              }
            });
          }
        }, (response) => {
          this.depoistRuleLoading = false;
        });
      },
      handleDepoistRuleChange(name) {
        const option = this.depoistRuleOptions.find((item) => {
          return item.name == name;
        })
        if (option) {
          this.modifyData.depositRuleId = option.id;
          this.modifyData.depositRuleName = option.name;
          this.modifyData.depositRuleCode = option.ruleCode;
          this.modifyData.depositRuleVersion = option.version;
          this.modifyData.userScopeValue = option.userScopeValue;
        }
      }
    },
    components: {
      lineNew,
      lineDetail
    },
  };

</script>

<style scoped lang="scss">
  @import "../../../common/css/myElementv2.scss";

  .agreement-detail {
    background: #f5f5f5;
    margin: -10px -15px;
    padding-top: 1px;
    box-sizing: border-box;
  }

  .info-box {
    margin-top: 5px;
    font-size: 14px;
    color: #000000;
    line-height: 36px;
  }

  .select-box {
    margin-top: 16px;
  }

  .select-wrap {
    padding: 24px;
    margin: 0 8px;
    background: white;
    margin: 8px 0;
  }

  .content-wrap {
    margin-top: 8px;
    background: white;
    padding: 24px;
    clear: both;

    &__tag {
      padding: 1px 8px;
      background: #bcbcbc;
      border-radius: 2px;
      font-size: 14px;
      line-height: 24px;
      font-weight: normal;
      color: #ffffff;
      margin-left: 16px;
      display: inline-block;
    }

    &__title {
      margin: 0;
      padding: 0;
      height: 32px;
      line-height: 32px;
      font-size: 16px;
    }

    &__btn {
      float: right;
    }

    .el-table {
      margin-top: 16px;
    }
  }

  .ope-box {
    .el-button+.el-button {
      margin-left: 0;
    }
  }

  .el-button--default {
    border: 1px solid#FF6D00;
    color: #ff6d00;
  }

  .el-button--primary {
    background-color: #ff6d00;
    border-color: #ff6d00;
    color: #fff;
  }

  .btn-box {
    float: right;
    padding-right: 24px;
  }

  .btn-big {
    width: 102px;
  }

  .tip {
    margin: 6px 0 36px 40px;
    color: #666666;

    span {
      margin-right: 50px;
    }
  }

  .mile-dialog>>>.el-form-item__label {
    color: #000000;
  }

  h3 {
    font-weight: bold;
  }

  /deep/ .listBox1 .el-form-item {
    margin-bottom: 20px !important;
  }

  /deep/ .listBox1 .el-form-item .el-form-item__content .el-input .el-input__inner {
    height: auto !important;
    line-height: 40px !important;
  }

  /deep/ .listBox1 .el-form-item__error {
    margin-top: 5px;
  }

  .saas-detail-dialog {
    .line-name {
      font-family: PingFangSC-Medium;
      font-size: 20px;
      color: #000000;
      margin-bottom: 16px;
      display: flex;
      align-items: center;
      margin-left: 24px;

      .line-img {
        display: inline-block;
        height: 45px;
        width: 40px;
        background: url("../../../common/images/line.png");
        background-size: cover;
        margin-right: 15px;
      }
    }

    .list-row {
      display: flex;
      justify-content: space-between;
      margin-left: 60px;
      margin-right: 60px;
      margin-bottom: 12px;

      .list-col {
        width: 30%;
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #000;

        .list-col-label {
          color: #888;
        }
      }
    }

    .line-transit {
      padding-top: 23px;
      border-top: 1px solid #e9e9e9;
      margin: 24px 60px 50px 60px;

      .line-transit-title {
        font-family: PingFangSC-Medium;
        font-size: 16px;
        color: #000000;
        margin-bottom: 20px;
      }
    }
  }

  .basic-title {
    margin: 24px 60px 20px 60px;
    font-family: PingFangSC-Medium;
    font-size: 16px;
    color: #000000;
  }

  .clickSpan {
    color: #409eff;
    cursor: pointer;
  }


  .new-el-select {
    box-sizing: border-box;

    /deep/.el-input__inner {
      height: 36px;
      line-height: 36px;
    }
  }
.clearfix:after {
  content: "";
  height: 0;
  line-height: 0;
  display: block;
  visibility: hidden;
  clear: both;
}

.clearfix:after {
  *zoom: 1;
  /*针对IE6/IE7*/
}

</style>
